<%@page import="application.RestoService"%>
<%@page import="java.util.ArrayList"%>
<%@ include file="../includes/common.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ajout des plats</title>
<script language="javascript">
	function validate(food) {
		if (food.name_food.value.length == 0) {
			alert("Saisir le nom de plat!");
			food.name_foot.focus();
			return false;
		}
		return true;
	}

	function listCategory(category_list) {
		if (category_list.options[category_list.selectedIndex].value == '-1') {
			return;
		}
		category_list.form.elements['id_category'].value = category_list.options[category_list.selectedIndex].value;
	}
</script>

</head>
<body>
	<center>
		<form name="food" id="food" action="db_add_food.jsp" method="post"
			onSubmit="return validate(this)">

			<table width="" height="" border="0" bordercolor="#000000"
				style="border: 1px:solid">

				<tr valign="top">
					<td height="178">
						<table width="1115" border="0">
							<tr bgcolor="#3399FF">

								<td width="672" height="21" class="Style3">Ajout des plats</td>
								<td bgcolor="#3399FF"><div align="right">
										<span class="Style2"><a href="category_view.jsp">Gestion
												des categories</a> | <a href="food_view.jsp">Gestion des plats</a> |
											<a href="#">TOTO | TATA </a> </span>
									</div></td>
							</tr>



							<tr>
								<th height="33" colspan="2"><div align="center">
										<%
											food = (String) session.getAttribute("name_food");
											session.removeAttribute("name_category");
											if (food != null)
												out.print(food);
										%>
									</div></th>
							</tr>


							<tr>
								<td width="179">&nbsp;</td>
								<td width="480">&nbsp;</td>
							</tr>
							<tr>
								<th>Category</th>

								<td> <input type="text"
									name="id_category" value="" id="id_category" /> <br /> <select
									onChange="listCategory(this);">
										<option value="-1">--- Select ---</option>
										<%
											food = (String) session.getAttribute("name_food");
											session.removeAttribute("name_category");
											if (food != null)
												out.print(food);

											ArrayList<ArrayList<String>> categories = new ArrayList<ArrayList<String>>();
											RestoService resto = new RestoService();
											ArrayList<String> category = new ArrayList<String>();
											categories = resto.listAllCategory();
											for(int i = 0; i < categories.size(); i++)
											{
												category = categories.get(i);
										%>
										<option value="<%=category.get(0)%>"><%=category.get(1) %></option>
										<%
											}
										%>
								</select></td>

							</tr>
							<tr>
								<th>Nom de plat</th>

								<td><input name="name_food" type="text" class="text"
									id="name_food" value="" /></td>
							</tr>
							<tr>
								<th>Description</th>
								<td><textarea class="FormElement" name="description_food"
										id="description_food" cols="60" rows="10"></textarea></td>
							</tr>
							<tr>
								<th>Pays</th>
								<td><input name="country_food" type="text" class="text"
									id="country_food" value="" /></td>
							</tr>
							<tr>
								<th>Image</th>
								<td><input name="image_food" type="text" class="text"
									id="image_food" value="" /></td>
							</tr>
							<tr>
								<th>Prix</th>
								<td><input name="price" type="text" class="text" id="price"
									value="" /></td>
							</tr>


							<tr>
								<td class="submission" colspan="2"><div align="center">
										<input name="s" type="submit" class="button" value="ADD" /> <input
											name="Reset" type="reset" class="button" value="RESET" />
									</div></td>
							</tr>

							<tr>
								<th class="submission" colspan="2"><div align="center">
										<a href="food_view.jsp">List des plat</a>
									</div></th>
							</tr>
						</table>
				<tr>
					<td bgcolor="#3399FF"><div align="right"></div>
				</tr>
				<tr>
					<td class="Style8">Projet con&ccedil;u dans le cadre du cours
						de Gestion de projet</td>
				</tr>
				<tr>
					<td class="Style8">Par : Nguyen Quoc Khai et Nguyen Huu Nguyen</td>
				</tr>

			</table>
		</form>
	</center>
</body>
</html>